package javaStudy;

/**
 * Created by qq65827 on 2015/2/4.
 */
public class utils {

    public static char[] copyOfRange(char[] src, int start, int end) {

        int length = end - start;
        if (length <= 0) {
            throw new IllegalArgumentException(end + "end should  > start" + start);
        }
        char[] dest = new char[length];
        //下面写代码复制的逻辑
        for (int i = start,j=0; i < end; i++,j++) {
            char temp = src[i];
            dest[j] = temp;
        }

        return dest;
    }

    public static int[] copyOfRange(int[] src, int start, int end) {
        int length = end - start;
        if (length <= 0) {
            throw new IllegalArgumentException(end + "end should  > start" + start);
        }
        int[] dest = new int[length];
        int j =0;
        while (start < end) {
            dest[j++] = src[start++];
        }

      /*  for (int i = start, j = 0; i < end; i++, j++) {

            dest[j] = src[i];
        }*/
        return dest;
    }
}
